import React from 'react'
import { BrowserRouter as Router, Redirect, Route, NavLink, Switch } from 'react-router-dom';
import './my.css'

class Changename extends React.Component {
	
    constructor(props) {
		//console.log(props);
        super(props);
        this.state = {
			userid: localStorage.getItem("userid")
  	    };
		
    }
    componentDidMount() {
		//console.log('componentDidMount');
    }
	btn = () => {
		var name = document.getElementsByClassName('my-textarea')[0].value;
		//console.log(name);
		//现在获取到输入的name,要传到服务器上去:
		//获取id
		//console.log(this.state.userid)
		fetch('http://62.234.30.197:8088/userlist/gainame', {
			method: 'post',
			body: JSON.stringify({'userid':`${this.state.userid}`,'name':`${name}`}),
			headers: {
			    "Access-Control-Allow-Origin":"*",
			    'content-type': 'application/json'
			},
			mode: 'cors'
		})
		.then(res=>res.json())
		//.then(res=> {console.log(res)})
		this.props.history.push('/Mymsg')
		//window.location.reload(true)
	}
    render () {
		return (
        <div>
        	<div className='my-kuang'>
        		<span className='my-return' onClick={() => this.props.history.goBack()}>&lt;</span>
        		<span className='my-kuang-mid-txt'>编辑昵称</span>
        	</div>
        	<textarea className='my-textarea' rows="3" placeholder="请输入你的昵称"></textarea>
        	<button onClick={this.btn} className='btn'>确定</button>
        </div>
    );
  }
}
export default Changename